package com.he.datasource;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
 * 
 * TODO 多数据源配置
 *
 * @author hesh
 * 2016年3月22日 - 上午10:28:07
 */
@Configuration
public class GlobalDataConfiguration {
	@Bean(name="primaryDataSource")
	@Primary
	@ConfigurationProperties(prefix="datasource.primary")
	public DataSource primaryDataSource() {
		System.out.println("-------------------- primaryDataSource init ---------------------");
		return DataSourceBuilder.create().build();
	}
	
	@Bean(name="secondaryDataSource")
	@ConfigurationProperties(prefix="datasource.secondary")
	public DataSource secondaryDataSource() {
		System.out.println("-------------------- secondaryDataSource init ---------------------");
		return DataSourceBuilder.create().build();
	}
}
